-- 幻化/分解描述tips

local newFashionTipsView = class("newFashionTipsView",function()
    return ccui.Layout:create()
end)

function newFashionTipsView:ctor()
    local function createModuleNode(uiPath, uiNodeName, parent)
        local node = cc.uiloader:load( uiPath )
        local moduleNode = node:getChildByName( uiNodeName )
        moduleNode:retain()
        moduleNode:removeFromParent()
        parent:addChild( moduleNode )
        moduleNode:release()
        return moduleNode
    end
    self.mUINode = createModuleNode( Res.Tips_Fasion, "Panel", self )
    self:setContentSize( self.mUINode:getContentSize() )
    ccui.Helper:doLayout( self.mUINode )

    self._bindingText = self.mUINode:getChildByName( "binding" )
--    self._tltText = self.mUINode:getChildByName( "tlt" )
--    self._tltText_1 = self.mUINode:getChildByName("tlt_1")
    self._numText = self.mUINode:getChildByName( "num" )
--    self._icon = self.mUINode:getChildByName( "icon" )
--    self._icon_1 = self.mUINode:getChildByName("icon_1")
    local icons = {}
    for i = 1, 2 do
        local str
        if i == 1 then
            str = "icon"
        else
            str = "icon_" .. (i - 1)
        end
        local icon = self.mUINode:getChildByName(str)
        icon:setVisible(false)
        table.insert(icons, icon)
    end
    self._icons = icons

    local tlts = {}
    for i = 1, 2 do
        local str
        if i == 1 then
            str = "tlt"
        else
            str = "tlt_" .. (i - 1)
        end
        local tlt = self.mUINode:getChildByName(str)
        tlt:setVisible(false)
        table.insert(tlts, tlt)
    end
    self._tlts = tlts
end

function newFashionTipsView:setBindStr( bindStr )
    self._bindingText:setString( bindStr and bindStr or "" )
    if bindStr and "" ~= bindStr then
        self._bindingText:setVisible( true )
    else
        self._bindingText:setVisible( false )
    end
end

function newFashionTipsView:setTltStr(tltStr)
    for _, v in ipairs(self._tlts) do
        v:setVisible(false)
    end
    if not tltStr then return end

    if type(tltStr) == "table" then
        local len = math.min(#self._tlts, #tltStr)
        for i =1, len do
            local str = tltStr[i]
            if "" ~= str then
                if i == len then
                    str = string.format(L("lua_code_text_446"), str)
                end
                self._tlts[i]:setString(str)
                self._tlts[i]:setVisible(true)
            end
        end
    else
        if "" ~= tltStr then
            self._tlts[1]:setString(tltStr)
            self._tlts[1]:setVisible(true)
        end
    end
end

function newFashionTipsView:setIcon(icons)
    for _, v in ipairs(self._icons) do
        v:setVisible(false)
    end
    if not icons then return end

    if type(icons) == "table" then
        local len = math.min(#self._icons, #icons)
        for i = 1, len do
            self._icons[i]:loadTexture(icons[i])
            self._icons[i]:setVisible(true)
        end
    else
        self._icons[1]:loadTexture(icons)
        self._icons[1]:setVisible(true)
    end
end

return newFashionTipsView
